<?php

use yii\bootstrap\BootstrapPluginAsset;
use yii\helpers\Html;
use kartik\slider\Slider;

BootstrapPluginAsset::register($this);

$labelOptions = ['class' => 'control-label'];
$inputOptions = ['class' => 'form-control'];

//单选radio|select,复选checkbox,区间between,文字text,图片image,文件file
?>
<?php foreach ($model as $key => $value): ?>
    <div class="form-group">
        <?= Html::hiddenInput("TemplateConf[{$key}][meta_key]", $value['meta_key'], $inputOptions) ?>
        <?= Html::hiddenInput("TemplateConf[{$key}][meta_name]", $value['meta_name'], $inputOptions) ?>
        <?= Html::hiddenInput("TemplateConf[{$key}][type]", $value['type'], $inputOptions); ?>

        <div class="input-group">
            <?= Html::tag('span', $value['meta_name'], ['class' => 'input-group-addon']) ?>
            <?php switch ($value['type']): case 'radio': ?>
                <?= Html::radioList("TemplateConf[{$key}][meta_value]", $value['format_model_meta_value'], $value['format_meta_value'], $inputOptions); ?>
                <?php break; ?>
            <?php case 'select': ?>
                <?= Html::dropDownList("TemplateConf[{$key}][meta_value]", $value['format_model_meta_value'], $value['format_meta_value'], $inputOptions); ?>
                <?php break; ?>
            <?php case 'checkbox': ?>
                <?= Html::checkboxList("TemplateConf[{$key}][meta_value]", $value['format_model_meta_value'], $value['format_meta_value'], $inputOptions); ?>
                <?php break; ?>
            <?php case 'between': ?>
                <div class="form-control">
                    <b class="badge"><?= intval(reset($value['format_meta_value'])) ?></b>
                    &nbsp;
                    <?= Slider::widget([
                        'name' => "TemplateConf[{$key}][meta_value]",
                        'value' => $value['model_meta_value'] ? $value['model_meta_value'] : $value['meta_value'],
                        'sliderColor' => Slider::TYPE_INFO,
                        'pluginOptions' => [
                            'min' => intval(reset($value['format_meta_value'])),
                            'max' => intval(end($value['format_meta_value'])),
                            'step' => 1,
                            'range' => true,
                        ],
                        'options' => ['readonly' => empty($value['is_write']) ? true : false]
                    ]) ?>
                    &nbsp;
                    <b class="badge"><?= intval(end($value['format_meta_value'])) ?></b>
                </div>
                <?php break; ?>
            <?php case 'text': ?>

                <?= Html::textInput("TemplateConf[{$key}][meta_value]", $value['format_meta_value'], $inputOptions); ?>
                <?php break; ?>
            <?php case 'image': ?>
                <?= Html::fileInput("TemplateConf[{$key}][meta_value]", $value['format_meta_value'], $inputOptions); ?>
                <?php break; ?>
            <?php case 'file': ?>
                <?= Html::fileInput("TemplateConf[{$key}][meta_value]", $value['format_meta_value'], $inputOptions); ?>
                <?php break; ?>
            <?php default: ?>
            <?php endswitch; ?>
        </div>
    </div>
<?php endforeach; ?>